<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Proxy 与 Reflect</title>
</head>
<body>
  <script>
   const user = {
     name: 'tom',
     age: 12
   }

   // 创建代理对象
   const userProxy = new Proxy(user, {
    get (target, property, receiver) {
      console.log('get()', '监视到读取属性')

      // return target[property]
      return Reflect.get(target, property, receiver)
    },

    set(target, property, value, receiver) {
      console.log('set()', '监视到修改或添加属性')
      Reflect.set(target, property, value, receiver)
    },

    deleteProperty(target, property) {
      console.log('deleteProperty()', '监视到删除删除')
      Reflect.deleteProperty(target, property)
    }
   })

   // 通过代理读取属性
   //  console.log(userProxy.name) 
   
   // 通过代理修改属性
   //  userProxy.name = 'Jack'
   // 通过代理添加属性
  //  userProxy.sex = '男'

   // 通过代理删除属性
   delete userProxy.name


   console.log(user)



   
  </script>
</body>
</html>